package com.fansl.koala.quickdev.module.users.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fansl.koala.quickdev.common.enums.DeleteFlagEnum;
import com.fansl.koala.quickdev.module.users.entity.SysRole;
import com.fansl.koala.quickdev.module.users.mapper.SysRoleMapper;
import com.fansl.koala.quickdev.module.users.service.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统角色表 服务实现类
 * </p>
 *
 * @author fansl
 * @since 2020-03-20
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    /**
     * 根据code查询角色
     *
     * @param roleCode 角色code
     * @return 角色信息
     */
    @Override
    public SysRole getByCode(String roleCode) {
        if(StrUtil.isBlank(roleCode)){
            return null;
        }
        Wrapper<SysRole> queryWrapper = Wrappers.<SysRole>lambdaQuery()
                .eq(SysRole::getRoleCode,roleCode);
        return getOne(queryWrapper);
    }

    /**
     * 根据主键逻辑删除角色信息
     *
     * @param id 主键
     * @return TRUE/FALSE
     */
    @Override
    public Boolean deleteById(Long id) {
        SysRole sysRole = new SysRole();
        sysRole.setRoleId(id.intValue());
        sysRole.setDelFlag(DeleteFlagEnum.DELETED.getCode());
        return updateById(sysRole);
    }
}
